var i = getApp(), a = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), t = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js");

Page({
    data: {
        isLogin: !1,
        isLogining: !1,
        addressData: null
    },
    onLoad: function() {
        var a = this;
        wx.canIUse("hideHomeButton") && wx.hideHomeButton();
        var t = i.globalData.isLogin;
        this.setData({
            isLogin: t
        }, function() {
            t || a.login();
        });
    },
    onShow: function() {
        null !== t._cb && (this.setData({
            isLogining: !1
        }), t._cb = null);
        var a = i.globalData.chooseAddressItem;
        a && this.setData({
            addressData: a
        });
    },
    login: function() {
        var a = this;
        i.globalData.isLogin || this.data.isLogining || this.setData({
            isLogining: !0
        }, function() {
            t.login(function(i) {
                a.setData({
                    isLogining: !1
                }), 1001 === i && a.setData({
                    isLogin: !0
                });
            });
        });
    },
    goToMyAddress: function() {
        wx.navigateTo({
            url: "/pages/address/index?from=order"
        });
    },
    getOrder: function() {
        var t = this;
        if (i.globalData.isLogin) {
            if (!this.data.isLoading) {
                var s = this.data.addressData;
                s ? (this.setData({
                    isLoading: !0
                }), wx.showLoading(), a.get("/v1/currency/flowingwater", {
                    address_id: s.address_id
                }).then(function(i) {
                    if (wx.hideLoading(), t.setData({
                        isLoading: !1
                    }), 1001 === i.data.code) {
                        var a = i.data.response.data;
                        wx.navigateTo({
                            url: "/pages/pay/pay?from=activity&orderId=" + a.order_id + "&price=" + a.order_total_paid / 100
                        });
                    }
                }).catch(function() {
                    wx.hideLoading(), t.setData({
                        isLoading: !1
                    });
                })) : this.goToMyAddress();
            }
        } else this.login();
    }
});